import { isUrl } from '../utils/utils';

const menuData = [
  // {
  // name: 'Dashboard',
  // icon: 'dashboard',
  // path: 'dashboard',
  // hideInBreadcrumb: true,
  // hideInMenu: true,
  // authority: 'admin',
  // },
  {
    name: '性能分析',
    icon: 'zhibiaofenxi1',
    path: 'analytics',
    children: [
      {
        name: '指标概况',
        icon: 'zhibiaofenxi',
        path: 'summary/:list',
      },
      {
        name: 'SQL概况',
        icon: 'SH',
        path: 'sqls/:list',
      },
      {
        name: '资源概况',
        icon: 'url_2018',
        path: 'urls/:list',
      },
      {
        name: 'JMV概况',
        icon: 'xingnengjiankong',
        path: 'jmv/:list',
      },
    ],
  },
  {
    name: "监控告警",
    icon: "gaojing",
    path: 'alarm',
    children: [
      {
        name: '告警任务',
        icon: 'renwu',
        path: 'job/:list',
      },
      // {
      //   name: '告警日志',
      //   icon: 'rizhi1',
      //   path: 'log/:list',
      // },
    ],
  },
];

function formatter(data, parentPath = '/', parentAuthority) {
  return data.map(item => {
    let { path } = item;
    if (!isUrl(path)) {
      path = parentPath + item.path;
    }
    const result = {
      ...item,
      path,
      authority: item.authority || parentAuthority,
    };
    if (item.children) {
      result.children = formatter(item.children, `${parentPath}${item.path}/`, item.authority);
    }
    return result;
  });
}

export const getMenuData = () => formatter(menuData);
